class Index{
    constructor(){
        this.getData();
    }
    // 获取数据
   async getData(){
       let data=await axios.get('http://localhost:8888/goods/list?pagesize=4')
    let{code,list}=JSON.parse(data);
        console.log(code,list);

        // 判断是否请求成功
        if(code!=1)throw new Error('数据请求失败！');

    // 渲染页面
    let html='';
    list.forEach(goods => {
        html+=`
     <ul>
        <a href="../HTML/container.html?pid=${goods.goods_id}">
        <li class="sk_goods" pid="${goods.goods_id}">
            <img src="${goods.img_big_logo}" alt="">
            <h5 class="sk_goods_title">
            ${goods.title}</h5>
            <p class="sk_goods_price">
            <em>${goods.current_price}</em>
             <del>${goods.price}</del>
            </p>
        </li>
        </a>
    </ul>
        `
    });
    console.log(html)

    // 将数据追加到ul中
 this.$('.time_in ul').innerHTML=html;

    }

    $(ele){
       return document.querySelector(ele)
    }
}
new Index();